package io.lckgroup.modules.lck.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.lckgroup.common.utils.PageUtils;
import io.lckgroup.common.utils.R;
import io.lckgroup.modules.lck.entity.CommonFeedbackEntity;
import io.lckgroup.modules.lck.service.CommonFeedbackService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 用户反馈表
 *
 * @author srq
 * @email siruiqi@siruiqi.com
 * @date 2020-01-19 19:14:38
 */
@RestController
@RequestMapping("diancan/commonfeedback")
public class CommonFeedbackController {
    @Autowired
    private CommonFeedbackService commonFeedbackService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("diancan:commonfeedback:list")
    public R list(@RequestParam Map<String, Object> params) {
        IPage<Map<String, Object>> selectPage = commonFeedbackService.selectCommonFeedback(params);
        PageUtils pageUtils = new PageUtils(selectPage.getRecords(), (int) selectPage.getTotal(), (int) selectPage.getSize(), (int) selectPage.getCurrent());
        return R.ok().put("page", pageUtils);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("diancan:commonfeedback:info")
    public R info(@PathVariable("id") Long id) {
        CommonFeedbackEntity commonFeedback = commonFeedbackService.getById(id);

        return R.ok().put("commonFeedback", commonFeedback);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("diancan:commonfeedback:save")
    public R save(@RequestBody CommonFeedbackEntity commonFeedback) {
        commonFeedbackService.save(commonFeedback);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/dealCommonFeedback")
    @RequiresPermissions("diancan:commonfeedback:update")
    public R update(@RequestBody Long[] ids) {
        commonFeedbackService.updateBatchById(ids);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("diancan:commonfeedback:delete")
    public R delete(@RequestBody Long[] ids) {
        commonFeedbackService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
